package com.xidian.zhiancloud.service.cgs.ExamManager;

import com.xidian.zhiancloud.dao.ExamTypeMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.ExamType;
import com.xidian.zhiancloud.model.ExamTypeExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.xidian.zhiancloud.util.tools.ObjectUtil.isEmpty;

/**
 * @Author chenguosong
 * @Date 2020/11/26 0:31
 * @Mail 2581592671@qq.com
 */
@Service
public class ExamTypeService {

    @Autowired
    private ExamTypeMapper examTypeMapper;

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void add(ExamType examType) {
        if(!isEmpty(examType)){
            examTypeMapper.insert(examType);
        }else{
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void deletebyid(Long id) {
        examTypeMapper.deleteByPrimaryKey(id);
    }

    public List<ExamType> getListPlan(int current, int size) {
        ExamTypeExample examTypeExample = new ExamTypeExample();
        return examTypeMapper.selectByExampleWithRowbounds(examTypeExample, new RowBounds(current, size));
    }

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void update(ExamType examType) {
        if(!isEmpty(examType)){
            examTypeMapper.updateByPrimaryKeySelective(examType);
        }else{
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }
}
